export const changeBigCount = (value = 0) => {
  const strNum = String(value);
  let newValue = undefined;
  // 传入的是5位数或五位数以下直接返回
  if (strNum.length <= 5) {
    return strNum;
  // 传入的是五位数以上且小于八位数
  } else if (strNum.length > 5 && strNum.length <= 8) {
    newValue = strNum.slice(0, -4);
    return `${newValue} 万`;
  // 传入的是八位数以上且小于12位数
  } else if (strNum.length > 8 && strNum.length <= 12) {
    newValue = strNum.slice(0, -8);
    return `${newValue} 亿`;
  }
}

function fillZero(data) {
  if (data < 10) {
    return `0${data}`;
  }
  return data;
}

// 时间戳转为xxxx-xx-xx格式
export const changeTimeStamp = data => {
  const d = new Date(data);
  const year = d.getFullYear();
  const month = fillZero(d.getMonth() + 1);
  const day = fillZero(d.getDate());
  return `${year}-${month}-${day}`;
}

// 格式化毫秒,返回String型分秒对象
export const formatTime = time => {
  if (!time) return { min: '00', max: '00' };
  return {
    min: Math.floor(time / 60).toString().padStart(2, '0'),
    max: Math.floor(time % 60).toString().padStart(2, '0'),
  }
}

// 将毫秒转为xx:xx的形式
export const changeSeconds = date => {
  const d = new Date(date);
  const minutes = fillZero(d.getMinutes());
  const seconds =  fillZero(d.getSeconds());
  return `${minutes}:${seconds}`;
}